package com.etnet.streamserver.view.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.etnet.streamserver.format.FormatterFactory;
import com.etnet.streamserver.view.common.ViewFieldMapping;

public class ViewDataService {
    public Map<String, FieldInfo> getViewField() {
        return ViewFieldMapping.getInstance().getFieldmaps();
    }

    public String getCSVviewField(String key) {
        Map<String, FieldInfo> fieldmaps = ViewFieldMapping.getInstance().getFieldmaps();
        List<String[]> listData = new ArrayList<String[]>();
        if (key == null) {
            for (Entry<String, FieldInfo> entry : fieldmaps.entrySet()) {
                FieldInfo info = (FieldInfo) entry.getValue();
                String[] temp = { info.getName(), info.getId(), info.isEnable()+"", info.getReqType(), info.getTip() };
                listData.add(temp);
            }
        } else if (fieldmaps.containsKey(key)) {
            FieldInfo info = (FieldInfo) fieldmaps.get(key);
            String[] temp = { info.getName(), info.getId(), info.isEnable()+"", info.getReqType(), info.getTip() };
            listData.add(temp);
        }

        return FormatterFactory.getFormatter("arraycsv").format(listData);
    }
}